<template>
  <div class="app-container">
    <div class="header-box">
      <div class="address header-left">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="100px">
          <el-form-item label="代理商名称" prop="agentName">
            <el-input v-model="queryParams.agentId" placeholder="请输入代理商名称" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
            <el-date-picker style="width: 210px;" v-model="daterangeCreateTime" value-format="yyyy-MM-dd"
              type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
        </el-form>
      </div>
      <div class="button-right">
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </div>
    </div>
    <el-divider></el-divider>
    <div class="button-right">
      <el-button size="small" type="primary" icon="el-icon-download" @click="handleExport"
        v-hasPermi="['agentAdd:agentAdd:export']">导出</el-button>
      <el-button type="primary" size="small" icon="el-icon-coin" @click="handleRecharge"
        v-hasPermi="['agentAdd:agentAdd:export']">充值</el-button>
    </div>
    <el-table v-loading="loading" :data="agentAddList">
      <el-table-column label="序号" align="center" prop="id" width="80" />
      <el-table-column label="代理商名称" align="center" prop="agentName" />
      <el-table-column label="充值金额" align="center" prop="exchangeAmount" />
      <el-table-column label="操作人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="small" type="text" icon="el-icon-view" @click="handleUpdate(scope.row)"
            v-hasPermi="['agentAdd:agentAdd:edit']">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body label-position="left">
      <el-form ref="form" :model="form" label-width="100px">
        <!--        <el-form-item label="交易标识id，十位数字和字母组成" prop="exchangeMark">
          <el-input v-model="form.exchangeMark" placeholder="请输入交易标识id，十位数字和字母组成" />
        </el-form-item>
        <el-form-item label="商户id" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入商户id" />
        </el-form-item> -->
        <el-form-item label="代理商名称">
          <el-input v-model="form.agentName" disabled />
        </el-form-item>
        <el-form-item label="充值金额">
          <el-input v-model="form.exchangeAmount" disabled />
        </el-form-item>
        <el-form-item label="操作人">
          <el-input v-model="form.userName" disabled />
        </el-form-item>
        <el-form-item label="创建时间">
          <el-input v-model="form.createTime" disabled />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" disabled />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAgentAdd, getAgentAdd, delAgentAdd, addAgentAdd, updateAgentAdd } from "@/api/agentAdd/agentAdd";

export default {
  name: "AgentAdd",
  data() {
    return {
      daterangeCreateTime: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 代理商充值订单表格数据
      agentAddList: [],
      // 弹出层标题
      title: "查看",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        agentName: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      // rules: {
      //   exchangeMark: [
      //     { required: true, message: "交易标识id，十位数字和字母组成不能为空", trigger: "blur" }
      //   ],
      //   storeId: [
      //     { required: true, message: "商户id不能为空", trigger: "blur" }
      //   ],
      //   agentName: [
      //     { required: true, message: "代理商名称不能为空", trigger: "blur" }
      //   ],
      //   type: [
      //     { required: true, message: "消费类型 0代理商充值 1商家充值 2商家发起背调扣费 3对应代理商接口调用扣费不能为空", trigger: "change" }
      //   ],
      //   exchangeAmount: [
      //     { required: true, message: "交易金钱数额不能为空", trigger: "blur" }
      //   ],
      //   balance: [
      //     { required: true, message: "交易后余额不能为空", trigger: "blur" }
      //   ],
      //   userId: [
      //     { required: true, message: "用户id不能为空", trigger: "blur" }
      //   ],
      //   deptId: [
      //     { required: true, message: "部门id不能为空", trigger: "blur" }
      //   ]
      // }
    };
  },

  created() {
    this.getList();
  },
  activated(){
    this.getList();
  },
  methods: {
    /** 查询代理商充值订单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listAgentAdd(this.queryParams).then(response => {
        this.agentAddList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        exchangeMark: null,
        storeId: null,
        storeName: null,
        agentId: null,
        type: null,
        exchangeAmount: null,
        balance: null,
        content: null,
        dataId: null,
        imgUrl: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        userId: null,
        deptId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAgentAdd(id).then(response => {
        this.form = response.data;
        this.open = true;

      });
    },
    /** 提交按钮 */
    submitForm() {
      this.open = false;
      this.form = {}
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.id || this.ids;
    //   this.$modal.confirm('是否确认删除代理商充值订单编号为"' + ids + '"的数据项？').then(function() {
    //     return delAgentAdd(ids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    /** 导出按钮操作 */
    handleExport() {
      this.download('agentAdd/agentAdd/export', {
        ...this.queryParams
      }, `agentAdd_${new Date().getTime()}.xlsx`)
    },
    handleRecharge() {
      this.$router.push({ path: '/order/TopupOrder', query: { info: 'Agent' } });
    }
  }
};
</script>
